package com.itdct.onflow.system.common.handler

import com.itdct.onflow.core.config.OnflowConfig
import com.itdct.onflow.core.vo.RespVo
import com.itdct.onflow.system.log.mapper.SysApiLogMapper
import com.itdct.onflow.system.log.mapper.SysImportantApiLogMapper
import io.swagger.v3.oas.annotations.Hidden
import jakarta.servlet.http.HttpServletResponse
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import java.util.concurrent.ExecutorService

/**
 * @author Zhouwx
 * @date 2024/4/22 10:24:03
 * @version 1.0
 * @description
 */
@Hidden
@ControllerAdvice
class SysExceptionHandler(
    val onflowConfig: OnflowConfig,
    val sysApiLogMapper: SysApiLogMapper,
    val sysImportantApiLogMapper: SysImportantApiLogMapper,
    val logThreadPoolExecutor: ExecutorService
) {
    private val handleException = SysHandleException(onflowConfig, sysApiLogMapper, sysImportantApiLogMapper, logThreadPoolExecutor)

    @ResponseBody
    @ExceptionHandler(Exception::class)
    fun exception(e: Exception, response: HttpServletResponse): RespVo<*> {
        response.status = 500
        return handleException.handle(e, response)
    }
}